package com.mf.controller;

import com.mf.service.impl.SocketService;
import com.mf.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: SocketController
 * Package: com.mf.controller
 * Description:
 *
 * @Author: lmf
 * @Create: 2024/5/6 10:06
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/socket")
@Tag(name = "socket连接")
public class SocketController {
    @Resource
    private SocketService socketService;

    @GetMapping("/device/status")
    @Operation(summary = "设置设备状态")
    public Result<Void> setDeviceStatus(@RequestParam String code, @RequestParam String flag,
                                     @RequestParam String message) {
        if("1".equals(flag)){
            socketService.sendMessageToAllClients("dv,"+code+","+flag+","+message);
        }else {
            socketService.sendMessageToAllClients("dv,"+code+","+flag);
        }
        return Result.success(null);
    }

    @Operation(summary = "设置设备线状态")
    @GetMapping("/device/line/status")
    public Result<Void> setDeviceLineStatus(@RequestParam String line, @RequestParam String flag) {

        socketService.sendMessageToAllClients("line,"+line+","+flag);
        // 当用户调用此API时，向所有连接的客户端发送消息
        return Result.success(null);
    }
}
